<template>

    <div >

      <el-form ref="form" :model="form" label-width="80px" style="width: 100%">
        <el-form-item label="联系方式">
          <el-input placeholder="请输入手机号/邮箱地址" v-model="form.telMail"></el-input>
        </el-form-item>
        <el-form-item label="验证码">
          <el-input placeholder="请输入内容" v-model="form.code" >
            <el-button slot="append"  @click="getMessageCode">{{buttonName}}</el-button>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toNext" style="width: 100%">下一步</el-button>
        </el-form-item>
      </el-form>

    </div>

</template>

<script>
    export default {
        name: "getPassword",
        data(){
          return{
             form:{
               telMail:"",
               code:""
             },
            buttonName: "获取验证码",
            isDisabled: false,
            //nextDisable:false,
            time: 60
          }
        },
        methods:{
          toNext(){
            this.$axios.post(this.$gloableData.serverPath+"user/userReg/identical?code="+this.form.code).then(res=>{
              console.log(res.data)
              if (res.data==true){
                this.$store.state.telMail=this.form.telMail;
                this.nextDisable=false;

              }else {
                this.nextDisable=true;
                alert("信息不匹配,请核对后重新输入")
              }
            });
            this.$emit("YY")
          },
          getMessageCode(){
            if (this.form.tel==""){
              //console.log(this.form.tel)
              alert("请输入手机号")
              this.isDisabled=true
              window.location.reload()
            }else {
              let me = this;
              me.isDisabled = true;
              let interval = window.setInterval(function() {
                me.buttonName = '（' + me.time + '秒）后重新发送';
                --me.time;
                if(me.time < 0) {
                  me.buttonName = "重新发送";
                  me.time = 20;
                  me.isDisabled = false;
                  window.clearInterval(interval);
                }
              }, 2000);
            }
            this.$axios.post(this.$gloableData.serverPath+"auth/telcode/sg?phone="+this.$data.form.telMail).then(res=>{
              console.log(res.data)
            })
          }
        }
    }
</script>

<style scoped>

</style>
